<template>
  <!-- 租赁房产管理 -->
  <base-breadcrumb :title="$route.meta.title">
    <!-- 搜索 -->
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <!-- 表格 -->
    <a-card :bordered="false">
      <!-- <title-name :title="$route.meta.title" /> -->
      
      <!-- 表格 -->
      <list-table
          ref="table"
          row-key="id"
          :columns="columns"
          :request="loadData"
          :alert="true"
          show-size-changer
          show-quick-jumper
      >
        <a-button
          slot="prefix" 
          slot-scope="ref"
          v-btn-permission="'oa_016_add_02'"
          class="mb12"
          icon="plus"
          type="primary"
          @click="handleManage(2)"
        >
          新增
        </a-button>
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }}</span>
        <template
          slot="action"
          slot-scope="text, record"
        >
          <MoreButton>
          <a
            v-btn-permission="'oa_016_loo_01'"
            @click="handleManage(0, record)"
          >查看</a>
          <a
            v-btn-permission="'oa_016_edi_03'"
            @click="handleManage(1, record)"
          >编辑</a>
          <!-- 删除 -->
          <a
            class="del_btn"
            @click="handleRemoves([record.id])"
          >删除</a>
          </MoreButton>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
// import { STable } from '@/components' // 表格
import { getLeaseContractList, removeLeaseContract } from '@/api/office/propertyManagement' // api
import TreeSelectOrganization from '@/components/TreeSelectOrganization'
import Selector from '@/components/Select/Selector'
import BasePage from '@/views/basePage' // 基础配置
import SelectCompanyAndProject from '@/components/Select/SelectCompanyAndProject'
import OrgTreeSelect from '@/components/OrgTreeSelect/index'
const searchArr = [
  // 搜索框
  {
    name: '单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  {
    name: '房屋用途',
    valueKey: 'houseUseId',
    type: Selector,
    selectType: '3',
    urlType: 'office',
  },
]
const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    scopedSlots: { customRender: 'index' }
  },
  {
    title: '单位',

    dataIndex: 'deptStr',
  },
  {
    title: '申请人',
    ellipsis: true,
    dataIndex: 'applicantUserNameTel',
  },
  {
    title: '小区名称',
    ellipsis: true,
    dataIndex: 'placeName',
  },
  {
    title: '房屋地址',
    ellipsis: true,
    dataIndex: 'placeAddress',
  },
  {
    title: '面积(m²)',
    ellipsis: true,
    dataIndex: 'builtArea',
  },
  {
    title: '租金（元/月）',
    dataIndex: 'rentFeeAmount',
    ellipsis: true,
  },
  {
    title: '租赁期限',
    dataIndex: 'leaseDateStart',
    ellipsis: true,
    customRender(text, record, index) {
      return record.leaseDateStart + '-' + record.leaseDateEnd
    },
  },
  {
    title: '房屋用途',
    dataIndex: 'houseUseStr',
    ellipsis: true,
  },
  {
    title: '状态',
    dataIndex: 'statusStr',
    ellipsis: true,
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '180px',
    align: 'center',
    scopedSlots: { customRender: 'action' },
  },
]
export default {
  name:'a'+Date.now(),
  extends: new BasePage(),
  components: {
    // STable,
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {}, // 查询参数
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
        return getLeaseContractList(requestParameters).then((res) => {
          return res
        })
      }, // 加载数据方法 必须为 Promise 对象
      removeApi: { remove: removeLeaseContract }, // api
      editModel: 0,
      form: {},
      position:''
    }
  },
  mounted(){
    this.position=this.$currentPost()?.postCode
  },
  methods: {
    // 搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
    // 操作栏
    handleManage(type, record) {
      this.editModel = type
      let query = {
        editModel: type,
      }
      if (record && record.id) {
        query.id = record.id
      }
      this.$router.push({
        name: '/office/propertyManagement/leaseContract/updateLeaseContract',
        query,
      })
    },
  },
}
</script>
